<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>

<body>
  第一个值：<input type="text" id="txt1">
  <br>
  第二个值：<input type="text" id="txt2">
  <br>
  <div id="show"></div>
  <button id="btn">求和</button>
  <script>
    // document.getElementById("id名"); 通过id 获取元素
    var btn = document.getElementById("btn");
    var txt1 = document.getElementById("txt1");
    var txt2 = document.getElementById("txt2");
    var show = document.getElementById("show")
    btn.onclick = function () {
      // 元素.innerHTML 是给元素内部添加标签或文本
      show.innerHTML = sum(txt1.value, txt2.value)
    }
    function sum(a, b) {
      return Number(a) + Number(b)
    }
  </script>
</body>

</html>